package bb.lanxing.lib.devices.igpsport;

import com.garmin.fit.ActivityMesg;
import com.garmin.fit.DateTime;
import com.garmin.fit.Event;
import com.garmin.fit.EventMesg;
import com.garmin.fit.EventType;
import com.garmin.fit.FileEncoder;
import com.garmin.fit.FileIdMesg;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;

public class GetMultipleFitsCommand extends CommandBase {
    private String mFilename;
    private List<Long> mLocalTimes;

    public GetMultipleFitsCommand(String str, List<Long> list) {
        this.mFilename = str;
        this.mLocalTimes = list;
    }

    @Override
    public CommandType getCommandType() {
        return CommandType.getMultiActivities;
    }

    @Override
    public byte[] getCommandData() {
        try {
            File file = new File(this.mFilename);
            if (file.exists()) {
                file.delete();
            }
            FileEncoder fileEncoder = new FileEncoder(file);
            FileIdMesg fileIdMesg = new FileIdMesg();
            fileIdMesg.setType(com.garmin.fit.File.ACTIVITY_SUMMARY);
            EventMesg eventMesg = new EventMesg();
            eventMesg.setTimestamp(new DateTime(111L));
            eventMesg.setEvent(Event.getByValue((short) 32));
            eventMesg.setEventType(EventType.getByValue((short) 2));
            fileEncoder.write(fileIdMesg);
            fileEncoder.write(eventMesg);
            for (Long l : this.mLocalTimes) {
                long longValue = l;
                ActivityMesg activityMesg = new ActivityMesg();
                activityMesg.setTimestamp(new DateTime(longValue));
                activityMesg.setLocalTimestamp(longValue);
                fileEncoder.write(activityMesg);
            }
            fileEncoder.close();
            FileInputStream fileInputStream = new FileInputStream(file);
            int length = (int) file.length();
            byte[] bArr = new byte[length];
            fileInputStream.read(bArr, 0, length);
            fileInputStream.close();
            return bArr;
        } catch (Exception unused) {
            return null;
        }
    }
}
